package com.JackTang.demo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Jack Tang
 * @description
 * @create 2023-05-05 17:01
 */
// 演示 req 保存作用域 demo01 和 demo02
@WebServlet("/demo01")
public class Demo01Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1.向 req 保存作用域保存数据
        req.setAttribute("uname","lida");
        // 2.客户端重定向
//        resp.sendRedirect("demo02");

        // 3.服务器端转发
        req.getRequestDispatcher("demo02").forward(req,resp);
    }
}